﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Kokomo.Mirror.PeFormat
{
	[Description("COR 2.0 Header")]
	public class Cor20Header : PeHeaderStruct
	{
		public static readonly int ValidStructSize = 72;

		// Header versioning
		[DisplayName("Struct size")]
		[TypeConverter(typeof(HexConverter))]
		public uint StructSize { get; private set; }

		[NonSerializedProperty]
		[DisplayName("Is StructSize valid?")]
		public bool IsStructSizeValid { get { return this.StructSize == ValidStructSize; } }

		[DisplayName("Runtime version")]
		public Version RuntimeVersion { get; private set; }

		// Symbol table and startup information
		[DisplayName("Metadata")]
		public DataDirectoryEntry MetaData { get; private set; }
		
		[DisplayName("Flags")]
		public CorImageFlags Flags { get; private set; }

		// If COMIMAGE_FLAGS_NATIVE_ENTRYPOINT is not set, EntryPointToken represents a managed entrypoint.
		// If COMIMAGE_FLAGS_NATIVE_ENTRYPOINT is set, EntryPointRVA represents an RVA to a native entrypoint.
		[DisplayName("Entry point token or RVA")]
		[TypeConverter(typeof(HexConverter))]
		public uint EntryPointTokenOrRva { get; private set; }

		// Binding information
		[DisplayName("Resources")]
		public DataDirectoryEntry Resources { get; private set; }

		[DisplayName("Strong name signature")]
		public DataDirectoryEntry StrongNameSignature { get; private set; }

		// Regular fixup and binding information
		[DisplayName("Code manager table")]
		public DataDirectoryEntry CodeManagerTable { get; private set; }
		[DisplayName("V-table fixups")]
		public DataDirectoryEntry VTableFixups { get; private set; }
		[DisplayName("Export address table jumps")]
		public DataDirectoryEntry ExportAddressTableJumps { get; private set; }

		// Precompiled image info (internal use only - set to zero)
		[DisplayName("Managed native header")]
		public DataDirectoryEntry ManagedNativeHeader { get; private set; }
	}
}